define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template','form'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template,Form) {

    var Controller = {
        index: function () {
            // 基于准备好的dom，初始化echarts实例
            var myChart = Echarts.init(document.getElementById('echart'), 'walden');
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '',
                    subtext: ''
                },
                color: [
                    "#18d1b1",
                    "#3fb1e3",
                    "#626c91",
                    "#a0a7e6",
                    "#c4ebad",
                    "#96dee8"
                ],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: [__('Register user')]
                },
                toolbox: {
                    show: false,
                    feature: {
                        magicType: {show: true, type: ['stack', 'tiled']},
                        saveAsImage: {show: true}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: Config.column
                },
                yAxis: {},
                grid: [{
                    left: 'left',
                    top: 'top',
                    right: '10',
                    bottom: 30
                }],
                series: [{
                    name: __('Register user'),
                    type: 'line',
                    smooth: true,
                    areaStyle: {
                        normal: {}
                    },
                    lineStyle: {
                        normal: {
                            width: 1.5
                        }
                    },
                    data: Config.userdata
                }]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
            $(window).resize(function () {
                myChart.resize();
            });
            $(document).on("click", ".btn-refresh", function () {
                setTimeout(function () {
                    myChart.resize();
                }, 0);
            });

            $(".stat-col").on("click", function() {
                var that = this;
                console.log({type:$(this).attr('type'),start_date:$('.start_date').val()})
                $.ajax({
                    url: "dashboard/get_details",
                    type: "POST",
                    dataType: "json",
                    data: {type:$(this).attr('type'),start_date:$('.start_date').val()},
                    success: function (res) {
                        layer.open({
                            type: 1
                            ,area:["250px","250px"]
                            ,btn:["确定"]
                            ,title: '统计详情'
                            ,skin: 'layui-layer-prompt'
                            ,content: res
                            ,yes: function(index, layero){
                                layer.closeAll();
                            },success: function() {
                            }
                        });
                    }
                })
                
            });


            if(Config.is_task == 1){
                // 基于准备好的dom，初始化echarts实例
                var myChart = Echarts.init(document.getElementById('echarts'), 'walden');
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: '',
                        subtext: ''
                    },
                    color: [
                        "#18d1b1",
                        "#3fb1e3",
                        "#626c91",
                        "#a0a7e6",
                        "#c4ebad",
                        "#96dee8"
                    ],
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['任务浏览量统计表']
                    },
                    toolbox: {
                        show: false,
                        feature: {
                            magicType: {show: true, type: ['stack', 'tiled']},
                            saveAsImage: {show: true}
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: Config.task_column
                    },
                    yAxis: {},
                    grid: [{
                        left: 'left',
                        top: 'top',
                        right: '10',
                        bottom: 30
                    }],
                    series: [{
                        name: '任务浏览量统计表',
                        type: 'line',
                        smooth: true,
                        areaStyle: {
                            normal: {}
                        },
                        lineStyle: {
                            normal: {
                                width: 1.5
                            }
                        },
                        data: Config.task_data
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
            


            $(window).resize(function () {
                myChart.resize();
            });
            $(document).on("click", ".btn-refreshs", function () {
                setTimeout(function () {
                    myChart.resize();
                }, 0);
            });

            Form.events.datetimepicker($("form"));
        }
    };

    return Controller;
});
